package com.wanxi.controller;

import com.wanxi.model.DesignerModel;
import com.wanxi.model.ResultModel;
import com.wanxi.service.DesignerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * @author 杨金乾
 */
@Controller
@CrossOrigin(origins = "*")
public class DesignerController{
    @Autowired
    private DesignerService designerService;

    @Autowired
    SendMessageController sendMessageController;
    private String table="设计师";
    @RequestMapping("/back/designer/findAll")
    @ResponseBody
    @PreAuthorize("hasAuthority('subPermission') or hasAuthority('allPermission')or hasAuthority('unaccessible')")
    protected ResultModel designerFindAll(DesignerModel model){

        ResultModel resultModel = designerService.findAll(model);
        sendMessageController.findAllUserMessages(table);
//        6.返回给前端
        return resultModel;
    }

    @RequestMapping("/back/designer/findById")
    @ResponseBody
    @PreAuthorize("hasAuthority('subPermission') or hasAuthority('allPermission')or hasAuthority('unaccessible')")
    protected ResultModel designerFindById(DesignerModel model){
        ResultModel resultModel = designerService.findById(model);
        sendMessageController.findByIdUserMessages(table);
//        6.返回给前端
        return resultModel;
    }

    @RequestMapping("/back/designer/update")
    @ResponseBody
    @PreAuthorize("hasAuthority('subPermission') or hasAuthority('allPermission')")
    protected ResultModel designerUpdate(DesignerModel model){
        ResultModel resultModel = designerService.update(model);
        sendMessageController.updateMessages(table);
//        6.返回给前端
        return resultModel;
    }
}
